﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using Sora.HelpSystem.Package.Pages;

namespace Sora.HelpSystem.UI.WPF.Converters
{
    public class SummaryChildrenConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return FilterChildren(value);
        }

        private IEnumerable<HelpPage> FilterChildren(object value)
        {
            var children = value as IEnumerable<HelpPage>;

            if (children == null)
                yield break;
            else
            {
                var items = from child in children where child.IsSummaryVisible orderby child.Order select child;

                foreach (var child in items)
                {
                    yield return child;
                }
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
